/* hal_gpio.h */
#ifndef __HAL_GPIO_H__
#define __HAL_GPIO_H__

#include "hal_common.h"

/* data & logic level. */

/* data input. */
uint32_t GPIO_ReadPortInputLevel(GPIO_Type * base);

/* data output. */
void GPIO_WritePortOutputLevel(GPIO_Type * base, uint32_t val); /* for port. */
void GPIO_SetPinsOutputLevel(GPIO_Type * base, uint32_t pins, bool high);  /* for pins. */
void GPIO_TogglePinsOutputLevel(GPIO_Type * base, uint32_t pins);

/* direction. */
void GPIO_EnablePinsOutputDirection(GPIO_Type * base, uint32_t pins, bool enable);
void GPIO_EnablePinsInputDirection(GPIO_Type * base, uint32_t pins, bool enable);

/* event. */
uint32_t GPIO_GetPinEventStatusFlags(GPIO_Type * base);
void GPIO_ClearPinEventStatusFlags(GPIO_Type * base, uint32_t flags);

typedef enum
{
    GPIO_PinDigitalInputEventReq_Disabled = 0u,
    GPIO_PinDigitalInputEventReq_DmaOnRisingEdge = 1u,
    GPIO_PinDigitalInputEventReq_DmaOnFallingEdge = 2u,
    GPIO_PinDigitalInputEventReq_DmaOnEitherEdge = 3u,
    
    GPIO_PinDigitalInputEventReq_IntOnLogic0 = 8u,
    GPIO_PinDigitalInputEventReq_IntOnRisingEdge = 9u,
    GPIO_PinDigitalInputEventReq_IntOnFallingEdge = 10u,
    GPIO_PinDigitalInputEventReq_IntOnEitherEdge = 11u,
    GPIO_PinDigitalInputEventReq_IntOnLogic1 = 12u,
} GPIO_PinDigitalInputEventReq_Type;

typedef struct
{
    uint32_t DigitalFilterWidth; /* 5-bit. */
    bool EnableInvertInputLogic;
    GPIO_PinDigitalInputEventReq_Type InputEventReq; /* interrupt or dma. */
} GPIO_PinDigitalInputEventConf_Type;

void GPIO_SetPinDigitalInputConf(GPIO_Type * base, uint32_t pin, GPIO_PinDigitalInputEventConf_Type * conf);

#endif /* __HAL_GPIO_H__ */

